using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ModWatch;

public partial class ModWatcher_CustomModWatcher : System.Web.UI.Page, IModWatchContainer
{

	public ModManager _modManager;
	public ModManager ModManager
	{
		get
		{
			if (_modManager == null)
				_modManager = new ModManager();
			return _modManager;
		}
	}

	protected void btnSave_Click(object sender, EventArgs e)
	{
		ModManager.SaveChanges();
	}

	private void Page_PreRender(object sender, EventArgs e)
	{
		lblLastServed.Text = DateTime.Now.ToString();
		if (ModManager.IsDirty())
			lblServerChange.Text = "Yes";
		else
			lblServerChange.Text = "No";
	}

	protected void cmwIntModWatcher_SavingChanges(object sender, CustomModWatcherSaveEventArgs e)
	{
		int currentValue;
		if (int.TryParse(txtInput.Text, out currentValue))
			e.SavedValue = currentValue;
		else
			e.SavedValue = null;
	}

	protected void cmwIntModWatcher_CheckingChange(object sender, CustomModWatcherCheckChangeEventArgs e)
	{
		int? savedValue = (int?)e.SavedValue;
		int currentValue;
		if (int.TryParse(txtInput.Text, out currentValue))
		{
			if (currentValue != savedValue)
				e.HasChanged = true;
		}
		else if (savedValue != null)
		{
			e.HasChanged = true;
		}
	}

}
